//
//  CPYSongListTypeTableViewCell.m
//  TTMusic
//
//  Created by chenpengyu on 16/4/5.
//  Copyright © 2016年 cpy. All rights reserved.
//

#import "CPYSongListTypeTableViewCell.h"
#import "CPYSongListTypeChildrenCollectionViewCell.h"
#import "CPYSongListTypeChildrenModel.h"
#import "CPYSongListFinalSongTableViewCell.h"
@implementation CPYSongListTypeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
//        self.backgroundColor = [UIColor whiteColor];
        self.collectionView = [[TTMusicBaseCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_flowLayout];
//        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerClass:[CPYSongListTypeChildrenCollectionViewCell class] forCellWithReuseIdentifier:@"CPYSongListTypeChildrenCollectionViewCellIdentifier"];
        [self.contentView addSubview:_collectionView];
    }
    return  self;
    
}
- (void)layoutSubviews {
    [super layoutSubviews];
    _collectionView.frame = self.bounds;
    _flowLayout.itemSize = CGSizeMake((SysWidth - 25) / 4, 50);
    _flowLayout.minimumLineSpacing = 5;
    _flowLayout.minimumInteritemSpacing = 5;
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _dataTypeChildrenSource.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CPYSongListTypeChildrenCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CPYSongListTypeChildrenCollectionViewCellIdentifier" forIndexPath:indexPath];
    CPYSongListTypeChildrenModel *typeChildrenModel = _dataTypeChildrenSource[indexPath.item];
    cell.typeLabel.text = typeChildrenModel.tag;
    return cell;
}

- (void)setDataTypeChildrenSource:(NSMutableArray *)dataTypeChildrenSource {
    _dataTypeChildrenSource = dataTypeChildrenSource;
    [_collectionView reloadData];
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    CPYSongListTypeChildrenModel *typeChildrenModel = _dataTypeChildrenSource[indexPath.item];
    [self.delegate sendTag:typeChildrenModel.tag];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
